export const requestTencentCaptcha = (appId: string, callback: any) => {
  function TCallback(res: any) {
    if (res.ret === 2) return;
    if (res.ret === 0) {
      if (res.ticket.startsWith('trerror_')) {
        return callback({ error: 'captchaError' });
      }
      callback(res);
    }
  }
  function loadErrorCallback() {
    const ticket = `trerror_1001_${appId}_${Math.floor(new Date().getTime() / 1000)}`;
    callback({
      ret: 0,
      randstr: `@${Math.random().toString(36).substr(2)}`,
      ticket,
      errorCode: 1001,
      errorMessage: 'jsload_error'
    });
  }
  function onCaptchaShow() {
    try {
      // @ts-ignore
      const captcha = new TencentCaptcha(appId, TCallback, {});
      captcha.show();
    } catch (error) {
      loadErrorCallback();
    }
  }
  onCaptchaShow();
}
